/** *******************************************************************
 * FlexDatabaseManager
 * Copyright (c) 2008 Jonnie Spratley. All Rights Reserved.
 * @author  Jonnie Spratley
 * @contact jonniespratley@gmail.com
 * @internal
 ******************************************************************* */
package com.jonniespratley.flexdatabasemanager.vo
{
	import com.jonniespratley.flexdatabasemanager.view.assets.AssetManager;
	
	import mx.utils.UIDUtil;
		

	[RemoteClass]
	[Bindable]
	public class FieldVO extends Object
	{
		public var aField:String;
		public var aType:String;
		public var aNull:String;
		public var aKey:String;
		public var aDefault:String;
		public var aExtra:String;
		
		[Embed(source='/assets/images/Row.swf', symbol='Row')]
		public var aMedia:Class;
		public var fieldUUID:String;
		
		public function  FieldVO( obj:Object = null )
		{			
			if ( obj != null )
			{
				this.aField = obj['Field'];
				this.aType = obj['Type'];
				this.aNull = obj['Null'];
				this.aKey = obj['Key'];
				this.aDefault = obj['Default'];
				this.aExtra = obj['Extra'];
			} 
		}
		
		public function get label():String
		{
			return aField + ' ' + aType;
		}
		
		public function get column():String
		{
			return aField;
		}
		
		public function get type():String
		{
			return 'field';
		}
		
		public function get isRequired():Boolean
		{
			var required:Boolean;
			
			if ( aNull == 'NO' )
			{
				required = false;			
			} else if ( aNull == 'YES' )
			{
				required = true;
			}
			
			return required;
		}
		
		public function get data():Object
		{
			return 'field';
		}
		
		public function get icon():Class
		{
			if ( aKey == 'PRI' )
			{
				return AssetManager.voKeyIcon;
			} else {
				return AssetManager.voFieldIcon;	
			}
		}
		
		public function get media():String
		{
			return 'assets/images/Field.swf';
		}
		
		public function createUUID():String
		{
			return UIDUtil.createUID();
		}
	}
}